package com.mtsmda.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.management.RuntimeErrorException;

public class TryCatch {

	public static void main(String[] args) {
		System.out.println(new ReturnTryCatch().openFile(1));
		System.out.println(new ReturnTryCatch().openFile(2));
		System.out.println(new ReturnTryCatch().openFile(15));
		System.out.println();
		System.out.println();
		System.out.println(new ReturnTryCatch().getDouble(0.99));
		System.out.println(new ReturnTryCatch().getDouble(-0.99));
		System.out.println(new ReturnTryCatch().getDouble(17.5));
		System.out.println("-----");
		System.out.println(new TryCatch().returnTryCatchFinally());
	}
	
	public int returnTryCatchFinally(){
		try{
			File file = new File("sdfsf");
			FileInputStream fileInputStream = new FileInputStream(file);
			throw new Exception();
//			return 10;
		}
		finally{
			return 20;
		}
	}
	
}

class ReturnTryCatch {

	@SuppressWarnings("finally")
	public double getDouble(Double d) {
		try {
			if (d.doubleValue() > 0.0 && d.doubleValue() < 1.0) {
				throw new Exception();
			}
			System.out.println("Not Exception!");
			if (d.doubleValue() >= 17.0) {
				return 3.0;
			}
			return 2.0;
		} catch (Exception e) {
			return 0.0;
		} finally {
			return 1.0;
		}
	}

	public int openFile(int c) {
		try {
			if (c == 1) {
				throw new FileNotFoundException("not found file");
			} else if (c == 2) {
				throw new Exception("Exception");
			}

			// throw new RuntimeErrorException(new Error(), "not found file");
		} finally {
			return c;
		}
	}

	public int openFile(int... c) {
		try {
			if (c[0] == 1) {
				throw new RuntimeErrorException(new Error(), "not found file");
			} else if (c[0] == 2) {
				throw new Error("Error");
			}

		} finally {
			return c[0];
		}
	}

}